package net.yambal.android.secretary_alarm;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.app.KeyguardManager.OnKeyguardExitResult;
//import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
//import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class ActivityAlarming extends Activity{
	private KeyguardManager keyguardmanager;
	private WakeLock wakelock;
	private KeyguardLock keyguardlock;
	//private SharedPreferences _sharedPreferences;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.alarm);
        
        Log.i("sa", "onCreate@Alarm");
        
		//_sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        
        Button btnStop = (Button)findViewById(R.id.btnStop);
        btnStop.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			}
		});
        
        //_alarm_controler.start();
   	}
	
	@Override
	public void onResume(){
		super.onResume();
		keyguardmanager = (KeyguardManager) getSystemService(this.KEYGUARD_SERVICE);
		keyguardlock = keyguardmanager.newKeyguardLock("FindMyPhone");
		keyguardlock.disableKeyguard();

		keyguardmanager.exitKeyguardSecurely(new OnKeyguardExitResult(){
			@Override
			public void onKeyguardExitResult(boolean success) {
				wakelock = ((PowerManager) getSystemService(ActivityAlarming.this.POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,"FindMyPhone");
				wakelock.acquire();
			}
		});
	}
	
	@Override
	public void onPause(){
		super.onPause();
		if (wakelock != null && wakelock.isHeld()) {
			wakelock.release();
		}
		keyguardlock.reenableKeyguard();
	}
	

}